﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RemoteDesktop
{
	public partial class RemoteForm : Form
	{
		private AxMSTSCLib.AxMsRdpClient4 rdpc = null;

		public RemoteForm()
		{
			InitializeComponent();
		}

		protected override void OnCreateControl()
		{
			rdpc = new AxMSTSCLib.AxMsRdpClient4();
			rdpc.OnDisconnected += new AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEventHandler(rdpc_OnDisconnected);
			this.Controls.Add(rdpc);
			rdpc.Dock = DockStyle.Fill;
//			rdpc.CreateControl();

			base.OnCreateControl();
		}

		public void Connect(ServerComputer server)
		{
			if (server == null)
			{
				MessageBox.Show("Error occured!");
				Close();
			}

			rdpc.Server = server.Server;
			rdpc.UserName = server.User;
			//rdpc.Domain = server.Password;
			if (server.Password != "")
			{
				rdpc.AdvancedSettings5.ClearTextPassword = server.Password;
			}
			rdpc.AdvancedSettings5.RedirectDrives = server.ShareDrives;
			rdpc.AdvancedSettings5.RedirectPrinters = server.SharePrinters;
			rdpc.ColorDepth = (int)server.ColorDepth;
			rdpc.Dock = DockStyle.Fill;
			rdpc.Connect();
		}

		private void rdpc_OnDisconnected(object sender, AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEvent e)
		{
			// дисконнектиться надо правильно
		}

	}	
}
